<template>
  <div
    @click="visible = false"
    class="jy-style-height research-box"
    :style="{
      background: `rgba(33, 33, 33, 1) url(${
        publicUrls + 'free/style2/publicStyle1Bg.png' + '?imageView2/3/format/webp'
      })`,
    }"
  >
    <div class="cultural-bg">
      <div class="research-heard">
        <i class="freeIcon" @click="blankHome">&#xe642;</i>
        <span class="titles">学术研究</span>
        <!-- v-if="!store.isMobileType" -->
        <div
          class="heard-right"
          @click.stop="visible = !visible"
          :style="list.length === 0 && parmas.typeId === 0 ? { opacity: '0', cursor: 'default' } : { opacity: '1' }"
        >
          <span>{{ TypeTitle }}</span>
          <i class="doorIcon" v-if="!visible">&#xe63a;</i>
          <i class="doorIcon" v-else>&#xe63e;</i>
          <div
            class="menu-box"
            :class="{ 'menu-box-active': visible }"
            :style="{ 'min-width': store.isMobileType ? '80px' : '60px' }"
          >
            <div
              :class="{ 'item-active': parmas.typeId === 0 }"
              class="pop-item pop-item-0 hw-click-cursor"
              @click.stop="setTypeId(0)"
            >
              <span
                >全部

                <div class="solider"></div>
              </span>
            </div>
            <div
              :class="{ 'item-active': parmas.typeId === item.id }"
              class="pop-item hw-click-cursor"
              @click.stop="setTypeId(item)"
              v-for="item in props.selectList"
              :key="item.id"
            >
              <span>
                {{ item.text }}
                <div class="solider"></div>
              </span>
            </div>
          </div>
        </div>
      </div>

      <scrollBox color="rgba(50, 43, 37, 1)" v-if="scrollheight && !loading" :byid="98627" :width="getScrollHeight">
        <template #solidBorderCon>
          <div class="researches-list" ref="scrollContainers" @scroll="handleScroll">
            <div class="is-null" v-if="list.length === 0 && !loading">
              <img :src="publicUrls + 'free/style2/exhibitsImg.png'" alt="" />
              <span>暂无学术研究</span>
            </div>
            <div
              class="item"
              :class="!store.isMobileType && 'item-hover'"
              v-else
              v-for="item in list"
              :key="item.id"
              @click="pathInfo(item.id)"
            >
              <div class="item-left">
                <div class="title1">
                  <div v-if="item.typeId" class="title1-color">
                    {{
                      item.typeId == 401792425939013
                        ? '课题研究'
                        : item.typeId == 401792277585989
                        ? '出版刊物'
                        : '论文论著'
                    }}
                  </div>
                  <div class="title1-names">{{ item.name }}</div>
                  <span class="title2">{{ item.publishedOn }}</span>
                </div>
                <p class="title3">{{ item.author }}</p>
              </div>
              <!-- <div class="item-right">
                <p class="title3">{{ item.author }}</p>
                <span class="title4">{{ item.publisher }}</span>
              </div> -->
            </div>
          </div>
        </template>
        <template #solidBorderEx>
          <div class="solidBorder-child"></div>
        </template>
      </scrollBox>
      <div class="content-door">
        <i class="iconfonts">&#xe6dd;</i>
        <span>永不落幕的展览与展示平台</span>
      </div>
    </div>
    <MenuNavigation />
  </div>
</template>

<script lang="ts">
export default defineComponent({
  name: 'style2',
});
</script>

<script setup lang="ts">
import { publicUrls } from '@/utils/minxin';
import { treeList } from '@/api/user/user';
import RightMenu from '../components/rightMenu.vue';
import Logo from '../components/logo.vue';
import FooterHome from '../components/footerHome.vue';
import PublicTitle from '../components/PublicTitle.vue';
import { useRouter, useRoute } from 'vue-router';
import { ref, watch, reactive, onActivated, nextTick, computed, defineComponent } from 'vue';
import { copyrightSave, copyrightInfo } from '@/api/templates/templates';
import { useProjectStore, commonDataStore } from '@/store';
import { storeToRefs } from 'pinia';
import scrollBox from '../scrollBox.vue';
import { investigationList } from '@/api/investigation/investigation';
import MenuNavigation from '@/freeComponents/menuNavigation/index.vue';

const props = defineProps({
  selectList: {
    type: Object,
  },
});
const scrollNumber = ref(0);
const heartbeat = ref(0); //页面心跳值
const store = useProjectStore();
const router = useRouter();
const scrollheight = ref();
const route = useRoute();
const current = ref(1);
const pageSize = ref(20);
const types = ref(true);
const visible = ref(false);
const parmas = reactive({
  value: '',
  pageNo: 1,
  pageSize: 20,
  typeId: 0,
});
const TypeTitle = ref('全部');
const list = ref([]);
const total = ref(0);
const loading = ref(false);
const scrollContainers = ref(null);

let viewportheight = window.innerHeight;
scrollheight.value = (viewportheight / 900) * 618;

const getScrollHeight = computed(() => {
  let rootNode = document.documentElement;

  // 获取计算后的样式
  let computedStyle = window.getComputedStyle(rootNode);

  // 读取字体大小（注意这里返回的可能是一个包含单位的字符串，如"16px"）
  let fontSize = computedStyle.fontSize;

  // 如果你需要一个数字值（不带单位）进行计算，你可能需要解析这个字符串
  // 例如，使用正则表达式或split()方法去除单位，并将结果转换为数字
  let fontSizeNumber = parseFloat(fontSize.replace(/[^0-9.-]/g, ''));
  let heights = (fontSizeNumber / 144) * 618;
  return heights;
});

const init = async (e?: number) => {
  try {
    if (loading.value) {
      return;
    }
    loading.value = true;
    let res = await investigationList(localStorage.getItem('projectId'), parmas);
    total.value = res.data.total;
    if (e) {
      list.value = [];
    }
    list.value = list.value.concat(res.data.data);
    loading.value = false;
    console.log(list.value);
  } catch {
    loading.value = false;
  }
};
const pageWheel = (event: any) => {
  //滚动
  const delta = Math.sign(event.wheelDelta || -event.detail);
  console.log(delta);
  if (delta > 0) {
    scrollContainers.value.scrollTop = scrollContainers.value.scrollTop - 50;
  } else {
    scrollContainers.value.scrollTop = scrollContainers.value.scrollTop + 50;
  }
  event.preventDefault();
  // rightScroll
};
const setTypeId = (e: any) => {
  if (e === 0) {
    parmas.typeId = 0;
    TypeTitle.value = '全部';
  } else {
    parmas.typeId = e.id;
    TypeTitle.value = e.text;
  }
  visible.value = false;
  parmas.pageNo = 1;
  init(2);
};
const handleScroll = () => {
  //滚动加载逻辑

  const scrollContainer = scrollContainers.value;
  const distanceToBottom = scrollContainer.scrollHeight - (scrollContainer.scrollTop + scrollContainer.clientHeight);
  scrollNumber.value = scrollContainer.scrollTop;
  if (distanceToBottom <= 50 && !loading.value && list.value.length < total.value) {
    parmas.pageNo = parmas.pageNo + 1;
    init();
  }
};
const pathInfo = (e: number) => {
  //查看详情
  router.push({
    name: route.meta.loopType ? 'templateresearchLoop' : 'templateresearch',
    query: {
      id: e,
    },
  });
};
init();
onActivated(() => {
  // heartbeat.value
  loading.value = true;
  nextTick(() => {
    loading.value = false;
  });
  if (heartbeat.value !== store.heartbeatCurrent) {
    scrollContainers.value.scrollTop = 0;
    scrollNumber.value = 0;
    parmas.typeId = 0;
    TypeTitle.value = '全部';
    parmas.pageNo = 1;
    init(2);
  } else {
    nextTick(() => {
      scrollContainers.value.scrollTop = scrollNumber.value;
    });
  }
  heartbeat.value = store.heartbeatCurrent;
});
const blankHome = () => {
  store.menuId = null;
  router.push({ name: route.meta.loopType ? 'exhibitionHome' : 'templateedit' });
};
</script>

<style scoped lang="less">
.research-box {
  width: 100%;
  padding: 0 84px;
  padding-bottom: 0px;
  background-size: contain !important;
  background-repeat: repeat !important;
  background-position: center !important;
}
.cultural-bg {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: rgba(153, 185, 182, 1);
  padding-top: 60px;
  position: relative;
}
.research-heard {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 60px;
  padding: 0 60px;
  .titles {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: ZKTSHIKTS--GB1, ZKTSHIKTS--GB1;
    font-size: 32px;
    color: #212326;
    line-height: 32px;
    background: #ffdc76;
    border-top: 1px solid #212326;
    border-bottom: 1px solid #212326;
  }
  span {
    font-family: SourceHanSerifCN-Bold;
    font-size: 36px;
    line-height: 56px;
    text-align: center;
    color: rgba(50, 43, 37, 1);
  }
  .freeIcon {
    font-size: 24px;
    line-height: 32px;
    color: rgba(50, 43, 37, 1);
    cursor: pointer;
  }
}
.heard-right {
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 200px;
  span {
    font-family: PingFang SC;
    font-size: 16px;
    line-height: 24px;
    color: rgba(33, 35, 38, 1);
  }
  .doorIcon {
    font-size: 16px;
    line-height: 16px;
    color: rgba(33, 35, 38, 1);
    margin-left: 4px;
  }
}
.menu-box {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 36px;
  right: 0;
  height: 0px;
  width: 7.777vw;
  min-width: 112px;
  padding: 0px 0px;
  background: #ffffff;
  border-radius: 6px;
  overflow: hidden;
  transition: height 0.3s;
  z-index: 123;
  transform: translateZ(0);
}
.menu-box-active {
  height: auto;
  padding: 12px 0px;
}
.pop-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 32px;
  margin-top: 8px;
  font-family: PingFang SC;
  font-size: 16px;
  font-weight: 400;
  line-height: 24px;
  color: rgba(50, 43, 37, 0.8);
  flex-shrink: 0;

  span {
    position: relative;
    flex-shrink: 0;
    color: rgba(50, 43, 37, 0.8);
  }
}
.pop-item-0 {
  margin-top: 0px;
}
.pop-item:hover {
  background: none;
  color: #212326;
  span {
    color: #212326;
  }
  // text-decoration: underline;
  .solider {
    opacity: 1;
  }
}
.item-active {
  position: relative;
  color: #212326;
  span {
    color: #212326;
  }
  .solider {
    opacity: 1;
  }
  // text-decoration: underline;
}
.solider {
  opacity: 0;
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 100%;
  height: 1px;
  background: #212326;
}
.researches-list {
  width: 100%;
  padding-left: 60px;
}
.researches-list::-webkit-scrollbar {
  display: none;
}
.is-null {
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: fixed;
  top: 50%;
  left: 0;
  transform: translate(0, -50%);
  img {
    width: 190px;
    height: 190px;
  }
  span {
    font-family: PingFangSC, PingFang SC;
    font-size: 16px !important;
    color: #212326;
    line-height: 22px;
    opacity: 26%;
  }
}
.item-hover {
  &:hover {
    background: rgba(91, 140, 135, 0.3);
  }
}
.item {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 72px;
  border-bottom: 1px solid rgba(33, 35, 38, 0.6);
  transition: all 0.5s ease;
  &:last-child {
    border: none;
  }
}
.item-left {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.title1 {
  display: flex;
  align-items: center;
  width: 100%;
  .title1-color {
    width: 76px;
    height: 24px;
    font-family: PingFangSC, PingFang SC;
    font-size: 14px;
    color: #212326;
    line-height: 24px;
    margin-bottom: 0;
    background: #ffdc76;
    border-radius: 4px;
    padding: 0 10px;
  }
  .title1-names {
    max-width: calc(100% - 300px);
    font-family: SourceHanSerifCN-Bold;
    font-size: 16px;
    line-height: 23px;
    color: rgba(0, 0, 0, 0.8);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-left: 8px;
  }
}
.title2 {
  font-family: Microsoft YaHei;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.38);
  line-height: 24px;
  padding-left: 12px;
  height: 26px;
}
.item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  width: 35vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.title3 {
  width: 32vw;
  overflow: hidden;
  font-family: SourceHanSerifCN, SourceHanSerifCN;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: SourceMedium;
  text-align: right;
  font-size: 16px;
  color: rgba(0, 0, 0, 0.59);
  line-height: 23px;
}
.title4 {
  width: 30vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: Microsoft YaHei;
  font-size: 14px;
  line-height: 26px;
  text-align: right;
  color: rgba(51, 51, 51, 0.5);
}
.solidBorder-child {
  width: 2px;
  height: 100%;
  background: #5b8c87;
  border-radius: 1px;
  opacity: 0.4;
}
::v-deep .templatestyle1-scroll-box-tumb {
  align-items: center;
  justify-content: center;
  top: -5px;
}

.content-door {
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 60%;
  position: absolute;
  bottom: 0;
  .iconfonts {
    font-size: 26px;
    color: rgba(255, 255, 255, 1);
    margin-bottom: 4px;
    line-height: 32px;
  }
  span {
    font-family: PingFang SC;
    font-size: 16px;
    line-height: 32px;
    color: rgba(255, 255, 255, 1);
    margin-left: 20px;
    padding-bottom: 7px;
  }
}
:deep(.unit-exbit-null-remarks-info) {
  margin: 0 60px;
  width: auto;
}
</style>